<?php
session_start();
include('fungsi_admin.php');
if (!empty($_SESSION['user'])){
?>
<html>
	<head>
		<title>BudiNews.com</title>
		<link rel="shortcut icon" href="../admin/css/mos-css/img/quote.png">
		<!-- Pemanggilan gambar favicon-->
		<link rel="stylesheet" type="text/css" href="../admin/css/mos-css/mos-style.css">
		<!--pemanggilan file css-->
	</head>
	<body>
		<div id="header">
			<div class="inHeader">
				<div class="mosAdmin">
					selamat datang di halaman Admin BudiNews.com
					<br/>
					<a href="keluar.php">Keluar</a>
				</div>
				<div class="clear">
				</div>
			</div>
		</div>
		<div id="wrapper">
			<div id="leftBar">
				<ul>
					<li>
						<a href="dashboard.php">Berita</a>
					</li>
					<li>
						<a href="kategori_tampil.php">Kategori</a>
					</li>
					<li>
						<a href="keluar.php">Keluar</a>
					</li>
				</ul>
			</div>
			<div id="rightContent">
				<h3>Halaman Pengaturan Berita</h3>
				<div style="float:right; padding: 0px 20px 10px 0px"><button class="button" onClick="document.location='tambah_berita.php'">Tambah Berita</button></div>
				<table class="data">
					<tbody>
						<tr class="data">
							<th class="data">ID</th>
							<th class="data">Judul</th>
							<th class="data">Detail</th>
							<th class="data">Waktu Post</th>
							<th class="data">Gambar</th>
							<th class="data">Status</th>
							<th class="data">Kategori</th>
							<th class="data" width="35px">Aksi</th>
						</tr>
						<?php
						include("../koneksi.php");
						$sql= "SELECT b.id_berita, b.judul, b.detail, DATE_FORMAT(b.waktu_post,'%e %M %Y %h:%i %p') as waktu, b.gambar, b.status, k.kategori 
						FROM berita b 
						JOIN kategori k ON k.id_kategori=b.id_kategori ORDER BY b.waktu_post DESC";
						$hasil= mysql_query($sql) or exit("Error query: <b>".$sql."</b>.");
						while($data= mysql_fetch_assoc($hasil)){ ?>
						<tr class="data">
							<td align="center" class="data">
							<?php echo $data['id_berita'];?>
							</td>
							<td class="data">
							<a href="ubah.php?id=<?php echo $data['id_berita'];?>" ><?php echo $data['judul'];?></a>
							</td>
							<td class="data">
							<?php echo substr($data['detail'], 0, 100);?>
							</td>
							<td class="data">
							<?php echo $data['waktu'];?>
							</td>
							<td class="data">
							<img src="../gambar/<?php echo $data['gambar'];?>" width="50px" height="50px"/>
							</td>
							<td class="data">
							<?php 
							switch ($data['status']) {
								case '1' :
									echo 'headline';
									break;
								case '2' :
									echo 'feature';
									break;
								case '3' :
									echo 'biasa';
									break;
								default :
									break;
								}
							?>
							</td>
							<td class="data">
							<?php echo $data['kategori'];?>
							</td>
							<td class="data">
							<a href="ubah.php?id=<?php echo $data['id_berita'];?>" title="Edit kategori <? echo $data['judul'];?>">
							<img src="../admin/css/mos-css/img/oke.png"/>
							</a>
							<a href="hapus.php?id=<?php echo $data['id_berita'];?>" onClick="return confirm('Apakah Mau Dihapus?');" title="Hapus kategori <? echo $data['judul'];?>">
							<img src="../admin/css/mos-css/img/hapus.png"/>
							</a>
							</td>
						</tr>
						<?php } ?>
					</tbody>
				</table>
			</div>
			<div class="clear">
			</div>
			<div id="footer">
				&copy; 2014 Created by |
				<a href="../pwl">BudiNews.com</a>
			</div>
		</div>
	</body>
</html>
<?php
}else{
echo "anda tidak berhak";
}
?>